<template>
  <dialog-editor ref="dialog"></dialog-editor>
</template>

<script>

  import DialogEditor from '@/components/DialogEditor'
  import dialogMixins from '@/utils/commonDialogMixins'

  export default {
    mixins: [dialogMixins],
    components: {DialogEditor},
    data () {
      return {
        visible: false,
        dataFormConfig: {
          id: {
            hidden: true
          },
          sampleNo: {
            label: '样品名称',
            placeholder: '样品名称'
          },
          sampleWeight: {
            label: '样品克数',
            type: 'number',
            max: 1000,
            default: 0
          },
          weightScope: {
            label: '克重误差(±)',
            type: 'String',
            default: '±'
          },
          clientId:{
            label: '客户名称',
            type: 'list',
            filterable: true,
            clearable: true,
            placeholder: '请选择客户名称',
            list: []
          },
          sampleDate: {
            label: '打样时间',
            type: 'date',
            placeholder: '请选择打样时间'
          },
          samplePicture: {
            label: '样品图片',
            type: 'uploadImage',
            imageType: 'uploadProductImage'
          },
          sampleDrawing: {
            label: '样品图纸',
            type: 'uploadImage',
            imageType: 'uploadProductPaper'
          },
          remark: {
            label: '样品备注',
            inputType: 'textarea',
            placeholder: '请输入样品备注'
          },
          status: {
            label: '状态',
            type: 'switch',
            activeValue: 1,
            inactiveValue: 0,
            default: 1
          }
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.initClientInfoList()

        this.$refs.dialog.initDialog({
          dataForm: this.dataForm,
          config: this.dataFormConfig,
          dataRule: this.getNeedDataRule('sampleNo', 'sampleWeight', 'clientId','sampleDrawing', 'sampleDate'),
          initApi: 'productApi/productSample',
          saveApi: 'productApi/saveProductSample',
          updateApi: 'productApi/updateProductSample',
          objectName: 'productSample'
        })
      }
    }
  }
</script>
